//
//  OAAddressDetailViewController.m
//  OASystem
//
//  Created by zhoupengfei on 16/1/18.
//  Copyright © 2016年 zpf. All rights reserved.
//

#import "OAAddressDetailViewController.h"
#import "MBProgressHUD.h"
#import "HttpTools.h"
@interface OAAddressDetailViewController ()
@property (weak, nonatomic) IBOutlet UIButton *mephone;

@property (weak, nonatomic) IBOutlet UIButton *mesend;
@property (weak, nonatomic) IBOutlet UIButton *upphone;
@property (weak, nonatomic) IBOutlet UIButton *upsend;
@property(nonatomic,strong)NSDictionary *dict;
//@property (weak, nonatomic) IBOutlet UILabel *first;
@property (weak, nonatomic) IBOutlet UIButton *phone;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *desLabel;

@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *shortLabel;

@property (weak, nonatomic) IBOutlet UILabel *telPhoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;

- (IBAction)sendSMSAction:(id)sender;

- (IBAction)callPhoneAction:(id)sender;
- (IBAction)shortsend:(id)sender;


- (IBAction)phone:(id)sender;
- (IBAction)shoryphone:(id)sender;

@end

@implementation OAAddressDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self requestData];
//     _phone.hidden = YES;
//    self.first.layer.cornerRadius = 10;
//    self.first.layer.masksToBounds = YES;
//    self.first.backgroundColor = [self randomColor];
}

-(UIColor *) randomColor
{
    CGFloat hue = ( arc4random() % 256 / 256.0 ); //0.0 to 1.0
    CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0,away from white
    CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; //0.5 to 1.0,away from black
    return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
    
}

-(void)requestData{
    [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
     NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray *  array = @[@{@"path":self.unid},@{@"userId":userId}];;
    [HttpTools requestWithURL:KExchother arrays:array method:@"contentTxl" success:^(id JSON) {
    NSLog(@"-----%@",JSON);
        [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
        NSArray * tempArray = JSON[@"data"];
        NSDictionary *dict = [tempArray firstObject];
    
        [self setupSubViews:dict];
        
    } failure:^(NSError *error) {
        [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
    }];
    
}

-(void)setupSubViews:(NSDictionary*)dict{
    
//    self.first.text = dict[@"surname"];
    self.nameLabel.text = dict[@"name"];
    self.desLabel.text = [NSString stringWithFormat:@"%@",dict[@"duties"]];
    self.phoneLabel.text = dict[@"telphone"];
    self.telPhoneLabel.text = dict[@"officephone"];
    self.typeLabel.text = dict[@"unit"];
    self.shortLabel.text = dict[@"cornet"];
if ([self.telPhoneLabel.text isEqualToString:@""]) {
    _phone.hidden = YES;
}
if ([self.phoneLabel.text isEqualToString:@""]) {
    _upsend.hidden = YES;
    _upphone.hidden = YES;
}

if ([self.shortLabel.text isEqualToString:@""]) {
    _mesend.hidden = YES;
    _mephone.hidden = YES;
}

    self.dict = dict;
}

- (IBAction)sendSMSAction:(id)sender {
     NSString * phone = [
     NSString stringWithFormat:@"sms://%@",self.dict[@"telphone"]];
    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:phone]];//发短信
}

- (IBAction)callPhoneAction:(id)sender {
    NSString * phone = [NSString stringWithFormat:@"tel://%@",self.dict[@"telphone"]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phone]];//打电话
}

- (IBAction)shortsend:(id)sender {
NSString * phone = [
     NSString stringWithFormat:@"sms://%@",self.dict[@"cornet"]];
    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:phone]];//发短信

}




- (IBAction)phone:(id)sender {
 NSString * phone = [NSString stringWithFormat:@"tel://%@",self.dict[@"officephone"]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phone]];//打电话
}

- (IBAction)shoryphone:(id)sender {
NSString * phone = [NSString stringWithFormat:@"tel://%@",self.dict[@"cornet"]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phone]];//打电话

}
@end
